﻿<?php
require_once './include/common.php';
$title="用户注册";
include ('include/head.php');

$ex='<div class="header"><ul class="nav nav-pills pull-right" role="tablist"><li role="presentation" class="active"><a href="index.php">首页</a></li><li role="presentation"><a href="login.php">会员登录</a></li><li role="presentation"><a href="reg.php">注册</a></li></ul><h3 class="text-muted" align="left">用户注册</h3></div><hr><h3>注册结果！！</h3>';
if(isset($_POST['username'])&&isset($_POST['password'])&&isset($_POST['email'])){
	if(!isset($_POST['submit'])){
		exit('<div class="header"><ul class="nav nav-pills pull-right" role="tablist"><li role="presentation" class="active"><a href="index.php">首页</a></li><li role="presentation"><a href="login.php">会员登录</a></li><li role="presentation"><a href="reg.php">注册</a></li></ul><h3 class="text-muted" align="left">用户注册</h3></div><hr><h3>非法访问！！</h3>');
	}
	$username = daddslashes($_POST['username']);
	$password = daddslashes($_POST['password']);
	$repass = daddslashes($_POST['repass']);
	$email = daddslashes($_POST['email']);
	$qq = daddslashes($_POST['qq']);
	$tel= daddslashes($_POST['tel']);
	$ip=get_ip();
	$time=time();
	//注册信息判断
	if(!is_name($username)){
		echo $ex.'用户名不符合规范！<a href="reg.php">返回</a>';
		include ('include/foot.php');
		exit;
	}
	if(strlen($password) < 6){
		echo $ex.'密码长度不符合规定!<a href="reg.php">返回</a>';
		include ('include/foot.php');
		exit;
	}
	if($password!=$repass){
		echo $ex.'两次密码不一样!<a href="reg.php">返回</a>';
		include ('include/foot.php');
		exit;
	}
	if(!is_email($email)){
		echo $ex.'错误：电子邮箱格式错误!<a href="reg.php">返回</a>';
		include ('include/foot.php');
		exit;
	}
	
	$sql = "SELECT regtime FROM w_user where ip='{$ip}'";
	$sth = $db->query($sql);
	$result=$sth->fetchAll();

	foreach($result as $value){
	if($time<($value[regtime]+86400)){
		echo $ex.'由于注册频繁，请稍后在注册!<a href="login.php">返回</a>';
		include ('include/foot.php');
		exit;
	}
	}
	$sql = "SELECT username FROM w_user where username='{$username}'";
	$sth = $db->query($sql);
	if($sth->fetch()){
		echo $ex.'该用户名已存在!<a href="reg.php">返回</a>';
		include ('include/foot.php');
		exit;
	}
	$sql = "SELECT email FROM w_user where email='{$email}'";
	$sth = $db->query($sql);
	if($sth->fetch()){
		echo $ex.'该用邮箱已注册!<a href="reg.php">返回</a>';
		include ('include/foot.php');
		exit;
	}
	//写入数据
	$passwordm = md5($password);	
	$regtime = time();
	$sql = "INSERT INTO `w_user` (`username`,`pwd`,`email`,`qq`,`tel`,`regtime`,`ip`)VALUES('{$username}','{$passwordm}','{$email}','{$qq}','{$tel}','{$regtime}','{$ip}')";
	$count = $db->exec($sql);
	//$id=$db->lastInsertId();
	if($count) {

		echo $ex.'注册成功！<br /><form action="login.php" method="post"><input type="hidden" name="username" value="'.$username.'"><input type="hidden" name="password" value="'.$password.'"><input type="hidden" name="cok" value="86400"><input type="submit" class="btn btn-primary btn-block" name="submit" value="点击登录"></form>';
	}
	else echo $ex.'注册失败!<br />3秒后自动跳转...<br />若无法跳转请<a href="reg.php">刷新</a>！<meta http-equiv="refresh" content="3;url=reg.php"><br />';
	include ('include/foot.php');
	exit;
}else{
	if(isset($_COOKIE['w_user'])&&isset($_COOKIE['w_userid']))
	{
		echo $_COOKIE['w_user']."您已登陆!<br />3秒后自动跳转...<br />若无法跳转请<a href='index.php?action=my'>刷新</a>！<meta http-equiv='refresh' content='3;url=index.php?action=my'><br />";
		exit;
	}else{
echo <<<HTML
    <div class="header">
        <ul class="nav nav-pills pull-right" role="tablist">
          <li role="presentation" class="active"><a href="index.php">首页</a></li>
          <li role="presentation"><a href="login.php">会员登录</a></li>
          <li role="presentation"><a href="reg.php">注册</a></li>
        </ul>
        <h3 class="text-muted" align="left">用户注册</h3>
      </div><hr>
	  <h3 class="form-signin-heading">免费注册</h3>
	  <form action="reg.php" class="form-sign" method="post">
	  用户名*(3-15字符长度，支持汉字、字母、数字及_)
	  <br><input type="text" class="form-control" name="username" value=""><br>
	  密码*(不得少于6位)
	  <input type="password" class="form-control" name="password" value=""><br>
	  重复密码*
	  <br><input type="password" class="form-control" name="repass" value=""><br>
	  邮箱*<br>
	  <small style="color:blue">注册后不可修改,找回账户唯一途径</small><br>
	  <input type="text" class="form-control" name="email" placeholder="你的QQ号码@qq.com"><br>
	  QQ号码<br>
	  <input type="text" class="form-control" name="qq" value=""><br>
	  手机号码<br>
	  <input type="text" class="form-control" name="tel" value=""><br>
	  <input type="submit" class="btn btn-primary btn-block" name="submit" value="确认注册"><br>
	  <a href="login.php" class="btn btn-default btn-block">返回登录</a>
	  </form>
	  <p>标注*的为必填项。</p>
HTML;
}
}
include ('include/foot.php');
?>
<BODY background="http://xinshi.qiniudn.com/BJ-qingxiu-1.jpg">
<body  background="http://zz.qqh.pw/1234.jpg"></body>